package com.lkm.app_ui.m.Imple.push;

import com.lkm.app_ui.AppConst;
import com.lkm.app_ui.help.TaskHelp;
import com.lkm.app_ui.log.SystemLogger;
import com.lkm.app_ui.m.Imple.push.captive.OnAppPushReceiver;
import com.lkm.app_ui.m.Imple.push.handle.PushCheckUpAppHandle;
import com.lkm.app_ui.m.Imple.push.handle.PushCmdHandle;
import com.lkm.app_ui.m.Imple.push.handle.PushDeviceInitHandle;
import com.lkm.app_ui.m.Imple.push.handle.PushScanHandle;
import com.lkm.app_ui.m.Imple.push.handle.PushSetGoodsButtonHandle;
import com.lkm.app_ui.m.Imple.push.handle.PushSetSteelyardRepairingHandle;
import com.lkm.app_ui.m.Imple.push.handle.PushUpSteelyardInfoHandle;
import com.lkm.app_ui.m.push.PushModule;
import com.lkm.market2_0.AppDataCache;
import com.mj.hx.yl.push.OnReceiverPushListener;
import com.mj.hx.yl.push.PushManage;
import com.mj.hx.yl.push.PushType;



public class PushModuleImpl implements PushModule, OnReceiverPushListener {

    public PushModuleImpl() {
        
        PushManage.init(AppConst.getApplication(), this, new PushType[]{
                new PushType(2, PushUpSteelyardInfoHandle.class),
                new PushType(3, PushSetGoodsButtonHandle.class),
                new PushType(5, PushSetSteelyardRepairingHandle.class),
                new PushType(9, PushDeviceInitHandle.class),
                new PushType(-1, PushScanHandle.class),
                new PushType(-2, PushCheckUpAppHandle.class),
                new PushType(-3, PushCmdHandle.class),
        });

        OnAppPushReceiver.regMe();
    }


    @Override
    public boolean onReceiverPush_TextMessage(String data) {
        return false;
    }

    private String pushKey = "";

    @Override
    public void onReceiverPushClientID(String clientid) {
        SystemLogger.onReceiverPushClientID(clientid);

        pushKey = clientid;
        AppDataCache.getInstance().setPushKey(pushKey);



//        AppMainModuleImple appMainModuleImple = (AppMainModuleImple) com.lkm.market2_0.Config.instance.getModuleManager().loadModule(AppMainModule.class);
        upPushKeyTask();
    }

    @Override
    public void upPushKeyTask() {
        TaskHelp.cancelById(UpPushKeyTask.getTaskId());
        UpPushKeyTask upPushKeyTask = new UpPushKeyTask(pushKey);
        upPushKeyTask.action();
        upPushKeyTask.execTask();
    }
}
